package com.cby.project.mvi

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.cby.project.mvi.bean.UserBean

/**
 * @description: MainAdapter
 *
 * @author ChenBaoyang
 * @date 2021/11/30 10:23
 */
class MainAdapter : RecyclerView.Adapter<MainAdapter.MainViewHolder>() {

    private val data = mutableListOf<UserBean>()


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int)
        = MainViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_main, parent, false))

    override fun onBindViewHolder(holder: MainViewHolder, position: Int) {
        holder.titleTv.text = data[position].userName
    }

    override fun getItemCount() = data.size

    fun submitList(userList: List<UserBean>) {
        data.clear()
        data.addAll(userList)
        notifyDataSetChanged()
    }


    inner class MainViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
        val titleTv = itemView.findViewById<TextView>(R.id.tv_title)
    }
}